/**
 * Created by PanJiaChen on 16/11/18.
 */

/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path);
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validUsername(str) {
  const valid_map = ["admin", "editor"];
  return valid_map.indexOf(str.trim()) >= 0;
}

export function validPrice(rule, value, callback) {
  if (!value) {
    callback(new Error("请填写门票价格"));
  } else {
    if (value < 0) {
      callback(new Error("请填写合适的价格"));
    } else {
      callback();
    }
  }
}
export function validPhone(rule, value, callback) {
  let reg = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
  if (!value) {
    callback(new Error("请输入手机号码"));
  } else {
    if (!reg.test(value)) {
      callback(new Error("请输入合法的手机号码"));
    } else {
      callback();
    }
  }
}
